package bootstrap

import (
	"go-mp-starter/global"

	"github.com/silenceper/wechat/v2"
	"github.com/silenceper/wechat/v2/cache"
	"github.com/silenceper/wechat/v2/miniprogram"
	miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
)

// InitWxapp 初始化微信小程序SDK
func InitWxapp() *miniprogram.MiniProgram {
	wxCfg := global.App.Config.Wxapp
	wc := wechat.NewWechat()
	memory := cache.NewMemory()

	cfg := &miniConfig.Config{
		AppID:     wxCfg.AppId,
		AppSecret: wxCfg.AppSecret,
		Cache:     memory,
	}
	mp := wc.GetMiniProgram(cfg)
	return mp
}
